@@ -41,49 +41,46 @@ public async Task<IDataResult> ActiveEmailByActivationCodeAsync(UserEmailActivat
41
41
ValidationTool . Validate ( new UserEmailActivateDtoValidator ( ) , userEmailActivateDto ) ;
42
42
43
43
var user = await DbContext . Users . AsNoTracking ( ) . FirstOrDefaultAsync ( u => u . EmailAddress == userEmailActivateDto . EmailAddress ) ;
44
- if ( user != null )
45
- {
46
- if ( string . Equals ( userEmailActivateDto . ActivationCode , user . VerificationCode ) )
47
- {
48
- user . IsEmailAddressVerified = true ;
49
- user . ModifiedDate = DateTime . Now ;
50
- var accessToken = CreateAccessToken ( user ) ;
51
- user . LastLogin = DateTime . Now ;
52
- UserToken userToken = new UserToken
53
- {
54
- UserId = user . Id ,
55
- Token = accessToken . Token ,
56
- TokenExpiration = accessToken . TokenExpiration ,
57
- RefreshToken = accessToken . RefreshToken ,
58
- RefreshTokenExpiration = accessToken . RefreshTokenExpiration ,
59
- CreatedByUserId = user . Id ,
60
- CreatedDate = DateTime . Now ,
61
- ModifiedByUserId = null ,
62
- ModifiedDate = null ,
63
- IpAddress = userEmailActivateDto . IpAddress ,
64
- IsActive = true ,
65
- IsDeleted = false
66
- } ;
67
- using ( TransactionScope transactionScope = new TransactionScope ( TransactionScopeAsyncFlowOption . Enabled ) )
68
- {
69
- DbContext . Users . Update ( user ) ;
70
- await DbContext . UserTokens . AddAsync ( userToken ) ;
71
- await DbContext . SaveChangesAsync ( ) ;
72
- transactionScope . Complete ( ) ;
73
- }
74
- return new DataResult ( ResultStatus . Success ,
75
- $ "{ user . EmailAddress } e-posta adresi başarıyla onaylanmıştır.", new UserWithTokenDto
76
- {
77
- User = Mapper . Map < UserDto > ( user ) ,
78
- UserToken = Mapper . Map < AccessToken > ( userToken )
79
- } ) ;
80
- }
44
+ if ( user == null )
45
+ throw new NotFoundArgumentException ( Messages . General . ValidationError ( ) , new Error ( $ "{ userEmailActivateDto . EmailAddress } e-posta adresine ait bir kullanıcı bulunamadı",
46
+ "EmailAddress" ) ) ;
47
+ if ( ! string . Equals ( userEmailActivateDto . ActivationCode , user . VerificationCode ) )
81
48
throw new NotFoundArgumentException ( Messages . General . ValidationError ( ) ,
82
49
new Error ( $ "{ userEmailActivateDto . ActivationCode } numaralı aktivasyon kodu doğru değildir.", "ActivationCode" ) ) ;
83
50
51
+ user . IsEmailAddressVerified = true ;
52
+ user . ModifiedDate = DateTime . Now ;
53
+ var accessToken = CreateAccessToken ( user ) ;
54
+ user . LastLogin = DateTime . Now ;
55
+ UserToken userToken = new UserToken
56
+ {
57
+ UserId = user . Id ,
58
+ Token = accessToken . Token ,
59
+ TokenExpiration = accessToken . TokenExpiration ,
60
+ RefreshToken = accessToken . RefreshToken ,
61
+ RefreshTokenExpiration = accessToken . RefreshTokenExpiration ,
62
+ CreatedByUserId = user . Id ,
63
+ CreatedDate = DateTime . Now ,
64
+ ModifiedByUserId = null ,
65
+ ModifiedDate = null ,
66
+ IpAddress = userEmailActivateDto . IpAddress ,
67
+ IsActive = true ,
68
+ IsDeleted = false
69
+ } ;
70
+ using ( TransactionScope transactionScope = new TransactionScope ( TransactionScopeAsyncFlowOption . Enabled ) )
71
+ {
72
+ DbContext . Users . Update ( user ) ;
73
+ await DbContext . UserTokens . AddAsync ( userToken ) ;
74
+ await DbContext . SaveChangesAsync ( ) ;
75
+ transactionScope . Complete ( ) ;
84
76
}
85
- throw new NotFoundArgumentException ( Messages . General . ValidationError ( ) , new Error ( $ "{ userEmailActivateDto . EmailAddress } e-posta adresine ait bir kullanıcı bulunamadı",
86
- "EmailAddress" ) ) ;
77
+ return new DataResult ( ResultStatus . Success ,
78
+ $ "{ user . EmailAddress } e-posta adresi başarıyla onaylanmıştır.", new UserWithTokenDto
79
+ {
80
+ User = Mapper . Map < UserDto > ( user ) ,
81
+ UserToken = Mapper . Map < AccessToken > ( userToken )
82
+ } ) ;
83
+
87
84
}
88
85
89
86
public AccessToken CreateAccessToken ( User user )
@@ -99,32 +96,31 @@ public async Task<IDataResult> ForgotPasswordAsync(string emailAddress)
99
96
throw new NotFoundArgumentException ( Messages . General . ValidationError ( ) , new Error ( "Mail adresi geçerli değil" , "emailAddress" ) ) ;
100
97
101
98
var user = await DbContext . Users . FirstOrDefaultAsync ( u => u . EmailAddress == emailAddress ) ;
102
- if ( user != null )
103
- {
104
- //create random password
105
- Random random = new Random ( ) ;
106
- const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ;
107
- string newPassword = new string ( Enumerable . Repeat ( chars , 6 )
108
- . Select ( s => s [ random . Next ( s . Length ) ] ) . ToArray ( ) ) ;
109
- //user update
110
- byte [ ] passwordHash , passwordSalt ;
111
- HashingHelper . CreatePasswordHash ( newPassword , out passwordHash , out passwordSalt ) ;
112
- user . PasswordHash = passwordHash ;
113
- user . PasswordSalt = passwordSalt ;
114
- user . ModifiedDate = DateTime . Now ;
115
- DbContext . Update ( user ) ;
116
- await DbContext . SaveChangesAsync ( ) ;
117
- //send new password to email
118
- _mailService . SendEmaiL ( new EmailSendDto
119
- {
120
- EmailAdress = user . EmailAddress ,
121
- Subject = "Şifremi Unuttum" ,
122
- Content = $ "<h5>Hesabınızda Şifre Yenileme Aksiyonu!</h5><br/><h5>Yeni şifreniz: { newPassword } </h5>"
123
- } ) ;
124
- return new DataResult ( ResultStatus . Success ,
125
- $ "{ user . EmailAddress } e-posta adresine yeni şifreniz gönderilmiştir.", Mapper . Map < UserDto > ( user ) ) ;
126
- }
99
+ if ( user == null )
127
100
throw new NotFoundArgumentException ( Messages . General . ValidationError ( ) , new Error ( "Böyle bir mail adresi bulunumamakta" , "emailAddress" ) ) ;
101
+
102
+ //create random password
103
+ Random random = new Random ( ) ;
104
+ const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ;
105
+ string newPassword = new string ( Enumerable . Repeat ( chars , 6 )
106
+ . Select ( s => s [ random . Next ( s . Length ) ] ) . ToArray ( ) ) ;
107
+ //user update
108
+ byte [ ] passwordHash , passwordSalt ;
109
+ HashingHelper . CreatePasswordHash ( newPassword , out passwordHash , out passwordSalt ) ;
110
+ user . PasswordHash = passwordHash ;
111
+ user . PasswordSalt = passwordSalt ;
112
+ user . ModifiedDate = DateTime . Now ;
113
+ DbContext . Update ( user ) ;
114
+ await DbContext . SaveChangesAsync ( ) ;
115
+ //send new password to email
116
+ _mailService . SendEmaiL ( new EmailSendDto
117
+ {
118
+ EmailAdress = user . EmailAddress ,
119
+ Subject = "Şifremi Unuttum" ,
120
+ Content = $ "<h5>Hesabınızda Şifre Yenileme Aksiyonu!</h5><br/><h5>Yeni şifreniz: { newPassword } </h5>"
121
+ } ) ;
122
+ return new DataResult ( ResultStatus . Success ,
123
+ $ "{ user . EmailAddress } e-posta adresine yeni şifreniz gönderilmiştir.", Mapper . Map < UserDto > ( user ) ) ;
128
124
}
129
125
130
126
public IEnumerable < OperationClaim > GetClaims ( User user )
0 commit comments