Ejemplo n.º 1
0
        public string UserRegistration(UserRegistrationDto userRegistrationDto)
        {
            using (SqlConnection conn = new SqlConnection(this.DBString))
            {
                var keyNew = SaltGenerator.GeneratePassword(10);
                userRegistrationDto.password = SaltGenerator.Base64Encode(
                    SaltGenerator.EncodePassword(userRegistrationDto.password, keyNew));

                using (SqlCommand cmd = new SqlCommand("spUserRegistration", conn)
                {
                    CommandType = CommandType.StoredProcedure
                })
                {
                    cmd.Parameters.AddWithValue("@email", userRegistrationDto.email);
                    cmd.Parameters.AddWithValue("@email_verified", true);
                    cmd.Parameters.AddWithValue("@full_name", userRegistrationDto.fullName);
                    cmd.Parameters.AddWithValue("@password", userRegistrationDto.password);
                    cmd.Parameters.AddWithValue("@phone_no", userRegistrationDto.phoneNo);
                    cmd.Parameters.AddWithValue("@registration_date", DateTime.Now);
                    cmd.Parameters.AddWithValue("@user_role", userRegistrationDto.userRole);
                    cmd.Parameters.AddWithValue("@key_new", keyNew);
                    cmd.Parameters.Add("@id", SqlDbType.Int).Direction = ParameterDirection.Output;

                    try
                    {
                        conn.Open();
                        cmd.ExecuteNonQuery();
                        string id = cmd.Parameters["@id"].Value.ToString();
                        if (id != "")
                        {
                            var GeneratedToken = this.GenerateJSONWebToken(Convert.ToInt32(id), "User");
                            MessagingService.Send("Verify Email", "Click on below given link to verify your email id " +
                                                  "<br/> <a href='http://*****:*****@gmail.com");
                            return(id);
                        }
                    }
                    catch
                    {
                        return(null);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            return("");
        }
Ejemplo n.º 2
0
        public string ResetPassword(ResetPasswordDto resetPasswordDto, string userId)
        {
            using (SqlConnection conn = new SqlConnection(this.DBString))
            {
                var keyNew = SaltGenerator.GeneratePassword(10);
                resetPasswordDto.password = SaltGenerator.Base64Encode(
                    SaltGenerator.EncodePassword(resetPasswordDto.password, keyNew));

                using (SqlCommand cmd = new SqlCommand("spUserResetPassword", conn)
                {
                    CommandType = CommandType.StoredProcedure
                })
                {
                    cmd.Parameters.AddWithValue("@user_id", userId);
                    cmd.Parameters.AddWithValue("@password", resetPasswordDto.password);
                    cmd.Parameters.AddWithValue("@key_new", keyNew);

                    try
                    {
                        conn.Open();
                        int id = cmd.ExecuteNonQuery();
                        if (id > 0)
                        {
                            return("Reset Password Successfully");
                        }
                    }
                    catch
                    {
                        return(null);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            return("Failed To Reset Password");
        }