public void CreateUserAccount(CreateUpdateUserAccountParams createAccountParams) { string spName = "[SP_Create_User_Account]"; SqlConnection conn = OpenConnection("ConnectionStringAccounts"); SqlCommand cmd = new SqlCommand(); cmd.CommandText = schema + "." + spName; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Connection = conn; // User name SqlParameter paramName = new SqlParameter("@Name", SqlDbType.NVarChar, 255, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Current, createAccountParams.Name); // User email SqlParameter paramEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 255, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Current, createAccountParams.Email); // User pwd hash SqlParameter paramPwdHash = new SqlParameter("@PwdHash", SqlDbType.NVarChar, 255, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Current, createAccountParams.PwdHash); // User pwd hash SqlParameter paramAccountKey = new SqlParameter("@AccountKey", SqlDbType.NVarChar, 255, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Current, createAccountParams.AccountKey); cmd.Parameters.Add(paramName); cmd.Parameters.Add(paramEmail); cmd.Parameters.Add(paramPwdHash); cmd.Parameters.Add(paramAccountKey); // TODO: uncomment when SP ready cmd.ExecuteNonQuery(); conn.Close(); }
public ResponseBase Any(CreateAccount request) { _logger.Log(EErrorType.Info, " ****** Call start: CreateAccount"); CreateAccountResponse response = new CreateAccountResponse(); try { GetUserAccountInfoParams accParams = new GetUserAccountInfoParams(); accParams.Email = request.Email; GetUserAccountInfoResult accResult = _dal.GetUserAccountInfo(accParams); if (accResult == null) { // creating account CreateUpdateUserAccountParams createParams = new CreateUpdateUserAccountParams(); createParams.Name = request.Name; createParams.Email = request.Email; createParams.AccountKey = EncodeUtils.CreateAccountKey(); createParams.PwdHash = EncodeUtils.GetPasswordHash(request.Pwd); createParams.ActivationCode = EncodeUtils.CreateActivationCode(); createParams.State = "Pending"; // TODO; change to consts _dal.CreateUserAccount(createParams); SendMailResponse mailerResponse = SendAccountConfirmEmail(createParams.Email, createParams.AccountKey, createParams.Name); response.Payload.AccountKey = createParams.AccountKey; response.Success = true; } else { response.Success = false; response.Errors.Add(new Error() { Code = EErrorCodes.UserAccountExists, Type = EErrorType.Error, Message = "User with specified data already exists" }); } } catch (Exception ex) { _logger.Log(ex); response.Success = false; response.Errors.Add(new Error() { Code = EErrorCodes.GeneralError, Type = EErrorType.Error, Message = string.Format("Unexpected error: {0}", ex.Message) }); } _logger.Log(EErrorType.Info, " ****** Call end: CreateAccount"); return(response); }
public ResponseBase Any(UpdateAccount request) { _logger.Log(EErrorType.Info, " ****** Call start: UpdateAccount"); UpdateAccountResponse response = new UpdateAccountResponse(); try { SessionInfo sessionParams = new SessionInfo(); sessionParams.SessionId = request.SessionToken; SessionInfo sessionInfo = _dal.GetSessionInfo(sessionParams, true); if (sessionInfo != null) { CreateUpdateUserAccountParams updateParams = new CreateUpdateUserAccountParams(); updateParams.AccountKey = sessionInfo.AccountKey; updateParams.Email = request.Email ?? null; updateParams.Name = request.Name ?? null; updateParams.PwdHash = !string.IsNullOrEmpty(request.Pwd) ? EncodeUtils.GetPasswordHash(request.Pwd) : null; updateParams.State = request.State ?? null; _dal.UpdateUserAccount(updateParams); response.Success = true; } else { response.Success = false; response.Errors.Add(new Error() { Code = EErrorCodes.InvalidSession, Type = EErrorType.Error, Message = "Invalid session" }); } } catch (Exception ex) { _logger.Log(ex); response.Success = false; response.Errors.Add(new Error() { Code = EErrorCodes.GeneralError, Type = EErrorType.Error, Message = string.Format("Unexpected error: {0}", ex.Message) }); } _logger.Log(EErrorType.Info, " ****** Call end: UpdateAccount"); return(response); }
public ResponseBase Any(ResetPassword request) { _logger.Log(EErrorType.Info, " ****** Call start: ChangePassword"); UpdateAccountResponse response = new UpdateAccountResponse(); try { // getting account details GetUserAccountInfoParams accInfoParams = new GetUserAccountInfoParams(); accInfoParams.Email = request.Email; GetUserAccountInfoResult accResult = _dal.GetUserAccountInfo(accInfoParams); if (accResult != null && accResult.Success) { string newPassword = EncodeUtils.GenerateRandomPassword(); // getting account details CreateUpdateUserAccountParams updateParams = new CreateUpdateUserAccountParams(); updateParams.AccountKey = accResult.AccountKey; updateParams.Email = request.Email; updateParams.PwdHash = EncodeUtils.GetPasswordHash(newPassword); _dal.UpdateUserAccount(updateParams); SendMailResponse mailerResponse = SendPasswordResetNotificationEmail(updateParams.Email, accResult.Name, newPassword); if (!mailerResponse.Success) { response.Errors.Add(new Error() { Code = EErrorCodes.MailSendFailed, Message = "Mail services returned errors. Check other errors", Type = EErrorType.Warning }); response.Errors.AddRange(mailerResponse.Errors); } response.Success = true; } else { response.Success = false; response.Errors.Add(new Error() { Code = EErrorCodes.UserAccountNotFound, Type = EErrorType.Error, Message = "No account found for the given email" }); } } catch (Exception ex) { _logger.Log(ex); response.Success = false; response.Errors.Add(new Error() { Code = EErrorCodes.GeneralError, Type = EErrorType.Error, Message = string.Format("Unexpected error: {0}", ex.Message) }); } _logger.Log(EErrorType.Info, " ****** Call end: ChangePassword"); return(response); }
public ResponseBase Any(ChangePassword request) { _logger.Log(EErrorType.Info, " ****** Call start: ChangePassword"); UpdateAccountResponse response = new UpdateAccountResponse(); try { SessionInfo sessionParams = new SessionInfo(); sessionParams.SessionId = request.SessionToken; SessionInfo sessionInfo = _dal.GetSessionInfo(sessionParams, true); if (sessionInfo != null) { // updating account details CreateUpdateUserAccountParams updateParams = new CreateUpdateUserAccountParams(); updateParams.AccountKey = sessionInfo.AccountKey; updateParams.Email = request.Email; updateParams.PwdHash = EncodeUtils.GetPasswordHash(request.Pwd); _dal.UpdateUserAccount(updateParams); // getting account details GetUserAccountInfoParams accInfoParams = new GetUserAccountInfoParams(); accInfoParams.AccountKey = sessionInfo.AccountKey; GetUserAccountInfoResult accResult = _dal.GetUserAccountInfo(accInfoParams); if (accResult != null) { SendMailResponse mailerResponse = SendPasswordChangedNotificationEmail(updateParams.Email, accResult.Name); if (!mailerResponse.Success) { response.Errors.Add(new Error() { Code = EErrorCodes.MailSendFailed, Message = "Mail services returned errors. Check other errors", Type = EErrorType.Warning }); response.Errors.AddRange(mailerResponse.Errors); } } response.Success = true; } else { response.Success = false; response.Errors.Add(new Error() { Code = EErrorCodes.InvalidSession, Type = EErrorType.Error, Message = "Invalid session" }); } } catch (Exception ex) { _logger.Log(ex); response.Success = false; response.Errors.Add(new Error() { Code = EErrorCodes.GeneralError, Type = EErrorType.Error, Message = string.Format("Unexpected error: {0}", ex.Message) }); } _logger.Log(EErrorType.Info, " ****** Call end: ChangePassword"); return(response); }
public ResponseBase Any(ActivateAccount request) { _logger.Log(EErrorType.Info, " ****** Call start: ActivateAccount"); ActivateAccountResponse response = new ActivateAccountResponse(); try { GetUserAccountInfoParams accParams = new GetUserAccountInfoParams(); accParams.Email = request.Email; GetUserAccountInfoResult accResult = _dal.GetUserAccountInfo(accParams); if (accResult != null) { if (accResult.ActivationCode == request.ActivationCode) { CreateUpdateUserAccountParams updateParams = new CreateUpdateUserAccountParams(); updateParams.AccountKey = accResult.AccountKey; updateParams.State = "active"; // TODO: need to change to consts _dal.UpdateUserAccount(updateParams); response.Success = true; } else { response.Success = false; response.Errors.Add(new Error() { Code = EErrorCodes.UserAccountNotValidated, Type = EErrorType.Error, Message = "Invalid activation code provided - account was not activated" } ); } } else { response.Success = false; response.Errors.Add(new Error() { Code = EErrorCodes.UserAccountNotFound, Type = EErrorType.Error, Message = "User account was not found." } ); } } catch (Exception ex) { _logger.Log(ex); response.Success = false; response.Errors.Add(new Error() { Code = EErrorCodes.GeneralError, Type = EErrorType.Error, Message = string.Format("Unexpected error: {0}", ex.Message) }); } _logger.Log(EErrorType.Info, " ****** Call end: ActivateAccount"); return(response); }